<template>
	<view class="container">
		<view class="user-section">
			<view class="user-info-box d-flex justify-between">
				<view class="d-flex align-items-center flex-item-extend" v-if="token.length > 0">
					<view class="portrait-box">
						<image class="portrait" :src="userinfo.avatar || '/static/missing-face.png'"></image>
					</view>
					<view class="info-box">
						<text class="username">{{ userinfo.username }}</text>
					</view>
				</view>
				<view class="d-flex align-items-center flex-item-extend" v-else>
					<view class="portrait-box">
						<image class="portrait" :src="userinfo.face || '/static/missing-face.png'"></image>
					</view>
					<view class="info-box">
						<button class="btn" @click="toLogin">登录</button>
					</view>
				</view>
			</view>
		</view>
		<view class="cover-container">
			<!-- 订单 -->
			<view class="order-section">
				<view class="order-item" @click="navigateTo('/pages/order/order?state=0')" hover-class="common-hover"
					:hover-stay-time="50">
					<text class="yticon icon-daifukuan"></text>
					<text>待付款</text>
				</view>
				<view class="order-item" @click="navigateTo('/pages/order/order?state=1')" hover-class="common-hover"
					:hover-stay-time="50">
					<text class="yticon icon-yishouhuo"></text>
					<text>已支付</text>
				</view>
				<view class="order-item" @click="navigateTo('/pages/order/order?state=2')" hover-class="common-hover"
					:hover-stay-time="50">
					<text class="yticon icon-shouhoutuikuan"></text>
					<text>已完成</text>
				</view>
				<view class="order-item" @click="navigateTo('/pages/order/order?state=3')" hover-class="common-hover"
					:hover-stay-time="50">
					<text class="yticon icon-shouye"></text>
					<text>已取消</text>
				</view>
				<view class="order-item" @click="navigateTo('/pages/order/order?state=4')" hover-class="common-hover"
					:hover-stay-time="50">
					<text class="yticon icon-shouye"></text>
					<text>已退款</text>
				</view>
			</view>
			<!-- 浏览历史 -->
			<view v-if="token.length > 0" class="history-section icon">
				<list-cell icon="icon-shezhi1" iconColor="#e07472" title="退出账号" border=""
					@eventClick="logout()"></list-cell>
			</view>
		</view>
	</view>
</template>
<script>
import listCell from '@/components/mix-list-cell';
import { mapState, mapMutations } from 'vuex';


export default {
	components: {
		listCell
	},
	data() {
		return {
			lookList: [],
			amount: '0',
			orderNum: {},
			recode: '',
			invitenum: '',
		};
	},
	computed: {
		...mapState('user', ['token', 'userinfo', 'looks', 'openid', 'wxMiniOpenId']),
		...mapState('sys', ['service']),
		...mapState('cart', ['mycart']),
	},
	onLoad() {
		// #ifdef MP-WEIXIN
		// #endif
	},
	onNavigationBarButtonTap(e) {
		const index = e.index;
		if (index === 0) {
			this.navigateTo('set');
		} else if (index === 1) {
			this.navigateTo('notice');
		}
	},
	onShow() {
	},
	onPullDownRefresh() {
	},

	methods: {
		...mapMutations('user', ['setToken', 'setUserInfo', 'setLooks']),
		...mapMutations('sys', ['setService']),
		...mapMutations('cart', ['clearCart']),
		logout() {
			uni.showModal({
				title: '确定要退出登录吗?',
				success: (res) => {
					if (res.confirm) {
						this.setToken('');
						this.setUserInfo({});
						this.setLooks([]);
						this.clearCart();
						uni.removeStorageSync('token');
						uni.removeStorageSync('userinfo');
						uni.removeStorageSync('looks');
						uni.removeStorageSync('openid');
						uni.removeStorageSync('wxMiniOpenId');
						uni.removeStorageSync('mycart');
						uni.removeStorageSync('mycartnum');
						uni.removeStorageSync('mycartprice');
						uni.navigateTo({
							url: '/pages/public/login'
						})
					}
				}
			})
		},
		navigateTo(url) {
			if (!this.token) {
				return uni.navigateTo({
					url: '/pages/public/login'
				})
			}
			uni.navigateTo({
				url: url
			})

		},
		xcxcheckPhone() {
			// if (this.wxMiniOpenId) {
			// 	this.$ajax.get('wechat/xcxcheckphone', { 'openid': this.wxMiniOpenId }).then(data => {
			// 		console.log(data);
			// 		if (0 == data.error && 1 == data.need_bind) {
			// 			return uni.navigateTo({
			// 				url: '/pages/public/bind'
			// 			})
			// 		}
			// 	})
			// }
		},
		toLogin() {
			return uni.navigateTo({
				url: '/pages/public/login'
			})
		},
		loadService() {
			// if (isEmptyObj(this.service)) {
			// 	this.$ajax.get('common/service', {}).then(data => {
			// 		if (0 == data.error) {
			// 			this.setService(data.data);
			// 		}
			// 	})
			// }
		},
		loadInfo() {
			// this.$ajax.get('member/info', { token: this.token }).then(data => {
			// 	if (0 == data.error) {
			// 		this.setUserInfo(data.data);
			// 		this.recode = data.data.invite_code;
			// 	} else {
			// 		this.$api.msg(data.msg);
			// 		if (data.relogin == 1) {
			// 			setTimeout(function () {
			// 				return uni.navigateTo({
			// 					url: '/pages/public/login'
			// 				})
			// 			}, 500)
			// 		}
			// 	}
			// })
		},
		loadLook() {
			var param = {
				token: this.token,
			}

			// this.$ajax.get('member/mylook', param).then(data => {
			// 	if (0 == data.error) {
			// 		this.setLooks(data.data);
			// 	}
			// 	if (data.relogin == 1) {
			// 		setTimeout(function () {
			// 			return uni.navigateTo({
			// 				url: '/pages/public/login'
			// 			})
			// 		}, 500)
			// 	}
			// })

		},
		toCallPhone() {
			uni.makePhoneCall({
				phoneNumber: this.service.phone
			});
		},
		navToGoodsDetail(item) {
			return uni.navigateTo({
				url: `/pages/product/product?data=${JSON.stringify({
					goods: item
				})}`
			});
		},

	}
};
</script>
<style lang="scss">
page {
	background-color: $page-color-base;
}

%flex-center {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
}

%section {
	display: flex;
	justify-content: space-around;
	align-content: center;
	background: #fff;
	border-radius: 10upx;
}

.user-section {
	background-color: $nav-bg;
	color: $nav-text;
	padding: 80upx 30upx 30upx 30upx;
	position: relative;

	.bg {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		filter: blur(1px);
		opacity: 0.7;
	}

	.btn-handle {
		font-size: $font-lg;
		height: 58rpx;
		line-height: 58rpx;
		color: #ffffff;
		margin-left: 10rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
		border-radius: 10rpx;

		&.color-blue {
			background-color: $font-color-spec;
		}

		&.color-pink {
			background-color: $uni-color-primary;
		}
	}

	.price {
		font-size: $font-lg+5upx;
		color: $font-color-price;
		line-height: 1;

		&:before {
			content: '￥';
			font-size: $font-color-price;
		}
	}
}

.user-info-box {
	height: 180upx;
	display: flex;
	align-items: center;
	position: relative;
	z-index: 1;

	.portrait {
		width: 130upx;
		height: 130upx;
		border: 1upx solid #fff;
		border-radius: 50%;
	}

	.username {
		font-size: $font-base ;
		color: $nav-text;
		margin-left: 20upx;
	}

	.btn {
		margin-left: 10upx;
		color: #FFFFFF;
		width: 100%;
		height: 60upx;
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 20upx;
		background-color: $nav-color-blue;
		font-size: $font-lg;
	}
}

.vip-card-box {
	display: flex;
	flex-direction: column;
	color: #f7d680;
	height: 240upx;
	background: linear-gradient(left, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.8));
	border-radius: 16upx 16upx 0 0;
	overflow: hidden;
	position: relative;
	padding: 20upx 24upx;

	.card-bg {
		position: absolute;
		top: 20upx;
		right: 0;
		width: 380upx;
		height: 260upx;
	}

	.b-btn {
		position: absolute;
		right: 20upx;
		top: 16upx;
		width: 132upx;
		height: 40upx;
		text-align: center;
		line-height: 40upx;
		font-size: 22upx;
		color: #36343c;
		border-radius: 20px;
		background: linear-gradient(left, #f9e6af, #ffd465);
		z-index: 1;
	}

	.tit {
		font-size: $font-base + 2upx;
		color: #f7d680;
		margin-bottom: 28upx;

		.yticon {
			color: $nav-bg;
			margin-right: 16upx;
		}
	}

	.e-b {
		font-size: $font-sm;
		color: #d8cba9;
		margin-top: 10upx;
	}
}

.cover-container {
	padding: 0 30upx;
	position: relative;
	padding-bottom: 20upx;

	.arc {
		position: absolute;
		left: 0;
		top: -34upx;
		width: 100%;
		height: 36upx;
	}
}

.tj-sction {
	@extend %section;

	.tj-item {
		@extend %flex-center;
		flex-direction: column;
		height: 140upx;
		font-size: $font-sm;
		color: #75787d;
	}

	.num {
		font-size: $font-lg;
		color: $font-color-dark;
		margin-bottom: 8upx;
	}
}

.order-section {
	@extend %section;
	padding: 28upx 0;
	margin-top: -20upx;

	.order-item {
		@extend %flex-center;
		width: 120upx;
		height: 120upx;
		border-radius: 10upx;
		font-size: $font-sm;
		color: $font-color-dark;
	}

	.yticon {
		font-size: 48upx;
		margin-bottom: 18upx;
		color: $nav-color-blue;
	}

	.icon-shouhoutuikuan {
		font-size: 44upx;
	}
}

.history-section {
	padding: 30upx 0 0;
	margin-top: 20upx;
	background: #fff;
	border-radius: 10upx;

	.sec-header {
		display: flex;
		align-items: center;
		font-size: $font-base;
		color: $font-color-dark;
		line-height: 40upx;
		margin-left: 30upx;

		.yticon {
			font-size: 44upx;
			color: #5eba8f;
			margin-right: 16upx;
			line-height: 40upx;
		}
	}

	.h-list {
		white-space: nowrap;
		padding: 30upx 30upx 0;

		image {
			display: inline-block;
			width: 160upx;
			height: 160upx;
			margin-right: 20upx;
			border-radius: 10upx;
		}
	}
}
</style>
